<!DOCTYPE html>
<html lang="en">
<head>
    <title>Count down</title>
</head>
<body>
	<div id="timer"></div>
	<script type="text/javascript">
		var maxtime = 60 * 60 * 12 * 1;    // 秒钟
		function CountDown() {
			if (maxtime >= 0) {

				var days = Math.floor(maxtime / 43200);
				var hours = Math.floor(maxtime % 43200 / 3600);
				var minutes = Math.floor(maxtime % 3600 / 60);
				var seconds = Math.floor(maxtime % 60);
				var msg = addZero(days) + "天" + addZero(hours) + "时" + 
						  addZero(minutes) + "分" + addZero(seconds) + "秒";
				document.getElementById("timer").innerHTML = msg;
				maxtime --;
			} else{
				clearInterval(timer);
				alert("时间到，结束!");
			}
		}

		function addZero(val){
			if(val < 10) return '0' + val;
			return val;
		}
		const timer = setInterval("CountDown()", 1000);  
	</script>
</body>
</html> 
    


